package com.hontech.bv.conn.serial

import com.hontech.bv.codec.decodeUint8
import com.hontech.bv.codec.encodeUint8

class Uint8 (var value: Int = 0) : SerialType {

    override fun size(): Int {
        return 1
    }

    override fun encode(buf: ByteArray, offset: Int) {
        encodeUint8(buf, offset, value)
    }

    override fun decode(buf: ByteArray, offset: Int) {
        value = decodeUint8(buf, offset)
    }

    fun signedValue(): Int {
        if ((value and 0x80) != 0) {
            return -(0x100 - value)
        }
        return value
    }
}



